package com.hitqz.robot.biz.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hitqz.robot.api.business.entity.CvdProductEntity;
import com.hitqz.robot.api.business.dto.CvdProductQueryDTO;
import com.hitqz.robot.api.business.dto.CvdProductSaveDTO;
import com.hitqz.robot.api.business.dto.CvdProductUpdateDTO;
import com.hitqz.robot.api.business.vo.CvdProductVO;
import com.hitqz.robot.biz.service.CvdProductService;
import com.hitqz.robot.common.core.util.HitConvertUtils;
import com.hitqz.robot.common.core.util.R;
import com.hitqz.robot.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * CVD产品管理
 *
 * @author kehanjiang
 * @date 2025-09-19 10:48:23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cvdProduct" )
@Tag(description = "cvdProduct" , name = "CVD产品管理管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CvdProductController {

    private final CvdProductService cvdProductService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dto CVD产品管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R<Page<CvdProductVO>> getCvdProductPage(@ParameterObject Page page, @ParameterObject CvdProductQueryDTO dto) {
	    dto = HitConvertUtils.emptyToNull(dto);
        return R.ok(cvdProductService.getCvdProductPage(page, dto));
    }


    /**
     * 通过id查询CVD产品管理
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    public R<CvdProductVO> getById(@PathVariable("id" ) Long id) {
        return R.ok(cvdProductService.getCvdProductById(id));
    }

    /**
     * 新增CVD产品管理
     * @param dto CVD产品管理
     * @return R
     */
    @Operation(summary = "新增CVD产品管理" , description = "新增CVD产品管理" )
    @SysLog("新增CVD产品管理" )
    @PostMapping
    public R<Boolean> save(@RequestBody CvdProductSaveDTO dto) {
        return R.ok(cvdProductService.saveCvdProduct(dto));
    }

    /**
     * 修改CVD产品管理
     * @param dto CVD产品管理
     * @return R
     */
    @Operation(summary = "修改CVD产品管理" , description = "修改CVD产品管理" )
    @SysLog("修改CVD产品管理" )
    @PutMapping
    public R<Boolean> updateById(@RequestBody CvdProductUpdateDTO dto) {
        return R.ok(cvdProductService.updateCvdProductById(dto));
    }

    /**
     * 通过id删除CVD产品管理
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除CVD产品管理" , description = "通过id删除CVD产品管理" )
    @SysLog("通过id删除CVD产品管理" )
    @DeleteMapping
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(cvdProductService.removeCvdProductBatchByIds(CollUtil.toList(ids)));
    }
}